package stream流第一遍.demo07;

import java.util.ArrayList;
import java.util.List;
import java.util.Optional;

/**
 * @author wql
 * @version 1.0
 * @date 2022/11/5 20:31
 */

public class Test {
    public static void main(String[] args) {
        List<Wql> list = new ArrayList<>();
        list.add(new Wql("张二",12,"男"));
        list.add(new Wql("李三",11,"男"));
        list.add(new Wql("王麻",3,"男"));
        list.add(new Wql("大炮",7,"男"));
        list.add(new Wql("益达",90,"男"));
        list.add(new Wql("只因",1000000001,"女"));
        //  聚合操作--统计元素个数
       // long count = list.stream().count();
       // System.out.println("count = " + count);

        //聚合操作--根据条件求最大的元素
        //Optional<Wql> max = list.stream().max((o1, o2) -> o1.getAge() - o2.getAge());
       // System.out.println("max = " + max);

        //聚合操作--根据条件求最小的元素
        Optional<Wql> min = list.stream().min((o1, o2) -> o1.getAge() - o2.getAge());
        System.out.println("min = " + min);
    }
}
class Wql{
    private String name;
    private Integer age;
    private String sex;

    public Wql(String name, Integer age, String sex) {
        this.name = name;
        this.age = age;
        this.sex = sex;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public Integer getAge() {
        return age;
    }

    public void setAge(Integer age) {
        this.age = age;
    }

    public String getSex() {
        return sex;
    }

    public void setSex(String sex) {
        this.sex = sex;
    }

    @Override
    public String toString() {
        return "Wql{" +
                "name='" + name + '\'' +
                ", age=" + age +
                ", sex='" + sex + '\'' +
                '}';
    }
}


